package com.ly.aps.system.provider.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ly.aps.system.model.dto.ItemDTO;
import com.ly.aps.system.provider.mapper.ItemMapper;
import com.ly.aps.system.provider.model.Item;
import com.ly.aps.system.provider.service.ItemService;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
@Slf4j
@RefreshScope
public class ItemServiceImpl extends ServiceImpl<ItemMapper, Item> implements ItemService {

	@Autowired
	private ItemMapper itemMapper;
	
	@Override
	public ItemDTO getAllItemList(Integer status, Integer type, String creator, String itemId, String time){
    	QueryWrapper<Item> queryWrapper = new QueryWrapper<>();
    	if(status!=null) {
    		queryWrapper.eq("is_active", status);
    	}
    	if(creator!=null&&!creator.equals("")) {
    		queryWrapper.eq("create_by", creator);
    	}
    	if(itemId!=null&&!itemId.equals("")) {
    		queryWrapper.eq("item_code", itemId);
    	}
    	if(time!=null&&!time.equals("")) {
    		queryWrapper.le("create_time", time.substring(11,21));
    		queryWrapper.ge("create_time", time.substring(0,10));
    	}
    	List<Item> list = itemMapper.selectList(queryWrapper);
    	ItemDTO itemDTO = new ItemDTO(list);
    	return itemDTO;
    }
	
    @Override
    public ItemDTO getItemList(Integer page, Integer count, Integer status, Integer type, String creator, String itemId, String time){
    	QueryWrapper<Item> queryWrapper = new QueryWrapper<>();
    	if(status!=null) {
    		queryWrapper.eq("is_active", status);
    	}
    	if(creator!=null&&!creator.equals("")) {
    		queryWrapper.eq("create_by", creator);
    	}
    	if(itemId!=null&&!itemId.equals("")) {
    		queryWrapper.eq("item_code", itemId);
    	}
    	if(time!=null&&!time.equals("")) {
    		queryWrapper.le("create_time", time.substring(11,21));
    		queryWrapper.ge("create_time", time.substring(0,10));
    	}
    	
    	Page<Item> ipage = itemMapper.selectPage(new Page<>(page, count), queryWrapper);
    	ItemDTO itemDTO = new ItemDTO(ipage);
    	return itemDTO;
    }
}
